//===========================================================================
//		在gcc 9.3.0版本下编译运行通过
//		在编译过程中需要添加C99标准
//		本代码片段演示内存与结构化的转换
//C语言的初始化规则: C语言初始化一个全局变量或static变量时，只能用常量赋值，不能用变量赋值！
//常见错误连接:https://www.cnblogs.com/laojie4321/p/4251215.html
//===========================================================================

#include <stdio.h>

#define MEM_LEN (12)

char mem[MEM_LEN];

struct TEST1
{
    /* data */
    char num;
    char age;
    int w;
    int h;
};

struct  TEST2
{
    /* data */
    void *entity;
    char type;
};

struct TEST1 t1Entity;

struct TEST1* const t1 = (struct TEST1*)mem;

const struct TEST2  t2[] = {
    {
        .entity = (void*)&((*t1).num),
        .type = 0
    },
    {
        .entity = (void*)&((*t1).age),
        .type = 0
    },
    {
        .entity = &t1->w,
        .type = 1
    },
    {
        .entity = &t1->h,
        .type = 1
    },
};

int main(){

    for(int i =0;i < MEM_LEN;i++){
        mem[i] = i;
    }

    *((char*)(t2[0].entity)) = 10;

    printf("num=%d\r\n",t1->num);
    printf("age=%d\r\n",t1->age);
    printf("w=%d\r\n",t1->w);
    printf("h=%d\r\n",t1->h);
    
    printf("end\r\n");


}


